package com.java.interview.i设计模式.模板模式;

/**
 * @Description:
 * @Auther: sixbing  QQ:414409451
 * @Date: 2018/11/4 11:49
 */
public class DoubleBubbleSorter extends BubbleSorter<double[]> {
    private double[] array;

    @Override
    protected void setArray(double[] array) {
        this.array = array;
    }

    @Override
    protected int getLength() {
        return array == null ? 0 : array.length;
    }

    @Override
    protected boolean needSwap(int index) {
        return array != null && (array[index] > array[index + 1]);
    }

    @Override
    protected void swap(int index) {
        double temp = array[index];
        array[index] = array[index + 1];
        array[index + 1] = temp;
    }
}
